package cn.lkx.servicecms.controller;


import cn.lkx.commonutils.R;
import cn.lkx.servicecms.entity.CrmBanner;
import cn.lkx.servicecms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端 后台控制器 （管理员用的）
 * </p>
 *
 * @author lkx
 * @since 2022-05-08
 */
@RestController
@RequestMapping("/servicecms/bannerAdmin")
@CrossOrigin
public class BannerAdminController {
    @Autowired
    private CrmBannerService bannerService;

    //分页查询轮播图banner
    @GetMapping("getBannerPage/{current}/{limit}")
    public R getBannerPage(@PathVariable Long current,@PathVariable Long limit){
        Page<CrmBanner> page  = new Page<>(current,limit);
        bannerService.page(page, null);
        return R.ok().data("items",page.getRecords()).data("total",page.getTotal());
    }
    //添加
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        bannerService.save(crmBanner);
        return R.ok();
    }
    //根据id获取banner 做修改回显
    @GetMapping("getById/{id}")
    public R getBannerById(@PathVariable String id){
        CrmBanner crmBanner = bannerService.getById(id);
        return R.ok().data("item",crmBanner);
    }
    //修改
    @PutMapping("updateById")
    public R updateById(@RequestBody CrmBanner banner) {
        bannerService.updateById(banner);
        return R.ok();
    }
    //删除
    @DeleteMapping("removeById/{id}")
    public R removeById(@PathVariable String id) {
        bannerService.removeById(id);
        return R.ok();
    }

}

